﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TaxiCaosWeb.Models.Usuario>" %>

<style>
form.cmxform2 label.error {
    color: white;
}

</style>    

 <script type="text/javascript">
    $(document).ready(function () {

        // validar formulario
        $("#formLogin").validate({
            submitHandler: function (form) {
                submitFormLogin(form);
            },
            rules: {
                ULogin: "required",
                Password: "required"
            }
        });

    });

    function submitFormLogin(form) {

        var $form = $(form);
        $("#login-box").hide();

        $.ajax({
            type: "POST",
            url: $form.attr('action'),
            data: $form.serialize(),
            error: function (xhr, status, error) {
                $("#loading-div-background").hide();
                $.msgBox({
                    content: error,
                    type: "error",
                    afterClose: function () {
                        $("#login-box").show();
                    }
                });
            },
            success: function (data) {
                $("#loading-div-background").hide();
                if (data.tipoMensaje == 'INFO') {
                    $.msgBox({
                        content: data.mensaje,
                        type: "info",
                        afterClose: function () {
                            if (clickReservaCliente == 0) {
                                window.location = data.redirectTo;
                            } else {
                                window.location = "/Reserva/Reserva";
                            }

                        }
                    });
                } else if (data.tipoMensaje == 'WARN') {
                    $.msgBox({
                        content: data.mensaje,
                        type: "alert",
                        afterClose: function () {
                            $("#login-box").show();
                        }
                    });
                }
            },
            beforeSend: function (data) {
                $("#loading-div-background").show();
            }
        });

        return false;
    }
</script>

<div id="login-box" class="login-popup">
        <a href="#" class="close"><img src="../../Content/imgs/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>
        <% using (Html.BeginForm("Autenticar", "Seguridad", FormMethod.Post, new { id = "formLogin", @class = "signin cmxform2" }))
               { %>           
                <fieldset class="textboxLogin">
            	<label class="username">
                <span>Usuario</span>
                <%: Html.TextBoxFor(model => model.ULogin) %>
                </label>
                <label class="password">
                <span>Contraseña</span>
                <%: Html.PasswordFor(model => model.Password)%>
                </label>
                
                <input id="btnSubmit" type="submit" class="submit buttonLogin" value="Ingresar"/>               
                <p>                
                Si no tiene una cuenta <a class="forgot" href="/Cliente/CrearCliente">Registrese Aquí</a>.
                </p>        
                </fieldset>
        
        <% } %>
</div>